// Copyright 2023 Huawei Cloud Computing Technology Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef VMI_TCP_CLIENT_SOCKET_H
#define VMI_TCP_CLIENT_SOCKET_H

#include "VmiTcpSocket.h"

class VmiTcpClientSocket : public VmiTcpSocket {
public:
    /*
     * @功能描述：TCP客户端套接字构造函数
     * @参数 [in] remoteIp：远端IP
     * @参数 [in] remotePort：远端端口
     */
    VmiTcpClientSocket(unsigned int remoteIp, unsigned short int remotePort);

    /*
     * @功能描述：TCP客户端套接字构造函数
     * @参数 [in] remoteIp：远端IP
     * @参数 [in] remotePort：远端端口
     * @参数 [in] localIp：本地IP，可选参数
     * @参数 [in] localPort：本地端口，可选参数
     */
    VmiTcpClientSocket(unsigned int remoteIp, unsigned short int remotePort, unsigned int localIp,
        unsigned short int localPort);

    /*
     * @功能描述：TCP客户端套接字构造函数
     * @参数 [in] socketOption：套接字选项
     * @参数 [in] remoteIp：远端IP
     * @参数 [in] remotePort：远端端口
     * @参数 [in] localIp：本地IP，可选参数
     * @参数 [in] localPort：本地端口，可选参数
     */
    VmiTcpClientSocket(unsigned int socketOption, unsigned int remoteIp, unsigned short int remotePort,
        unsigned int localIp, unsigned short int localPort);

    /*
     * @功能描述：析构函数，关闭通信套接字
     */
    ~VmiTcpClientSocket() = default;

    /*
     * @功能描述：连接TCP网络通信服务端
     * @返回值：0，连接成功；不等于0，连接失败
     */
    int Connect() override;

private:
    /*
     * @功能描述：创建客户端TCP套接字的帮助函数
     * @返回值：0表示成功，不为0表示失败
     */
    int CreateSocket();

    /*
     * @功能描述：设置socket参数选项
     * @参数 [in] socketFd：socket句柄
     * @返回值：成功返回0，小于0表示失败
     */
    int SetOptions(int socketFd);
};

#endif // VMI_TCP_CLIENT_SOCKET_H